<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" v-show="showSearch" :inline="true">
      <el-form-item label="描述词" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入描述词" clearable size="small" style="width: 240px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row type="flex" justify="space-between" class="mb8">
      <el-col :span="6" class="tag-group">
        <el-tag v-for="(item, index) in tagItems" :key="item.label"
          :effect="queryParams.withdraw === item.value ? 'dark' : 'plain'" style="margin-right: 10px"
          @click="handleClick(item)">
          {{ item.label }}
        </el-tag>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="tenantList">
      <el-table-column label="编号" align="center" prop="id" sortable />
      <el-table-column label="用户ID" align="center" prop="userId" />
      <el-table-column label="邀请人数" align="center" width="110" prop="inviteNum" sortable>
        <template slot-scope="scope">
          <el-button type="text" @click="handleInvite(scope.row)">{{ scope.row.inviteNum }}</el-button>
        </template>
      </el-table-column>
      <el-table-column label="消费金额(元)" align="center" width="120" prop="consumerMoney" sortable>
        <template slot-scope="scope">
          <span>￥{{ scope.row.consumerMoney }}</span>
        </template>
      </el-table-column>
      <el-table-column label="累计收益(元)" align="center" width="120" prop="totalEmployee" sortable>
        <template slot-scope="scope">
          <span>￥{{ scope.row.totalEmployee }}</span>
        </template>
      </el-table-column>
      <el-table-column label="已提现(元)" align="center" width="120" prop="haveWithdraw" sortable>
        <template slot-scope="scope">
          <span>￥{{ scope.row.haveWithdraw }}</span>
        </template>
      </el-table-column>
      <el-table-column label="收益余额(元)" align="center" width="120" prop="employeeRetain" sortable>
        <template slot-scope="scope">
          <span>￥{{ scope.row.employeeRetain }}</span>
        </template>
      </el-table-column>
      <el-table-column label="提现申请(元)" align="center" width="120" prop="withdrawApplication" sortable>
        <template slot-scope="scope">
          <span>￥{{ scope.row.withdrawApplication }}</span>
        </template>
      </el-table-column>
      <el-table-column label="上级收益余额(元)" align="center" width="150" prop="firstLevelEmployeeRetain" sortable>
        <template slot-scope="scope">
          <span>￥{{ scope.row.firstLevelEmployeeRetain }}</span>
        </template>
      </el-table-column>
      <el-table-column label="上上级收益余额(元)" align="center" width="170" prop="secondLevelEmployeeRetain" sortable>
        <template slot-scope="scope">
          <span>￥{{ scope.row.secondLevelEmployeeRetain }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="240" fixed="right" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" :disabled="!scope.row.withdrawId" @click="handleCheck(scope.row)">提现审批</el-button>
          <el-button size="mini" type="text" @click="handleOpenRecord(scope.row)">提现记录</el-button>
          <el-button size="mini" type="text" @click="handleUpdateMoney(scope.row)">修改收益余额</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 提现记录 -->
    <Record :dialogVisibleFlag.sync="dialogVisibleFlag" :userId="userId" :userName="userName" />

    <!-- 修改收益余额 -->
    <EmployeeMoney :dialogVisibleFlag.sync="moneyVisibleFlag" :userId="userId" :userName="userName" :employeeRetain="employeeRetain" />

    <!-- 提现审批 -->
    <WithdrawalAudit :dialogVisibleFlag.sync="remitVisibleFlag" :userId="userId" :userName="userName" :withdrawId="withdrawId" :withdrawApplication="withdrawApplication" />
  </div>
</template>
  
<script>
import { getExtendInfoList, saveExperienceRecord, removeExperienceRecord } from "@/api/shuiyin/shuiyin";
import Record from './components/Record.vue';
import EmployeeMoney from './components/EmployeeMoney.vue';
import WithdrawalAudit from './components/WithdrawalAudit.vue';

export default {
  name: "ExtendInformation",
  components: {
    Record,
    EmployeeMoney,
    WithdrawalAudit
  },
  data() {
    return {
      uploadAction: process.env.VUE_APP_BASE_API + "/common/ossUpload",
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 租户管理表格数据
      tenantList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        userInfo: null,
        withdraw: '',
        pageNum: 1,
        pageSize: 10,
      },
      tagItems: [
        {
          value: '',
          label: '全部'
        }, {
          value: true,
          label: '提现申请'
        }
      ],
      // 申请用户id
      userId: '',
      // 申请用户名
      userName: '',
      // 提现记录展开隐藏
      dialogVisibleFlag: false,
      // 收益余额展开隐藏
      moneyVisibleFlag: false,
      // 收益余额
      employeeRetain: 0,
      // 提现申请展开隐藏
      remitVisibleFlag: false,
      // 提现申请
      withdrawApplication: 0,
      // 提现申请id
      withdrawId: null,
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询租户管理列表 */
    getList() {
      this.loading = true;
      getExtendInfoList(this.queryParams).then(response => {
        this.tenantList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // tag标签点击事件
    handleClick(item) {
      this.queryParams.withdraw = item.value;
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 查看提现记录
    handleOpenRecord(row) {
      this.userId = row.userId;
      this.userName = row.userName;
      this.dialogVisibleFlag = true;
    },
    // 修改收益余额
    handleUpdateMoney(row) {
      this.userId = row.userId;
      this.userName = row.userName;
      this.employeeRetain = row.employeeRetain;
      this.moneyVisibleFlag = true;
    },
    // 提现申请
    handleCheck(row) {
      this.withdrawId = row.withdrawId;
      this.userId = row.userId;
      this.userName = row.userName;
      this.withdrawApplication = row.withdrawApplication;
      this.remitVisibleFlag = true;
    },
    // 点击邀请人数
    handleInvite(row) {
      this.$router.push("/detail/userId/" + row.userId);
    }
  }
};
</script>
<style>
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 90px;
  height: 90px;
  line-height: 90px;
  text-align: center;
}
.avatar {
  width: 90px;
  height: 90px;
  display: block;
}
</style>